/*
 *  Mfuns.h
 *  SSE
 *
 *
 */
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <time.h>
#include "rngs.h"
#include "rvgs.h"
#import "openGLheads.h"


///////////////////////////////////////////////////////////////////
// CONSTANTS
#define PI				3.14159
#define TWOPI			2*PI
#define DEGTORAD(deg)	(((deg) * PI) / 180.0)
#define RADTODEG(rad)	(((rad) * 180.0) / PI)
#define LOOPTIME		0.017
#define ROOTTHREE		1.7320508
#define TRUE			1
#define FALSE			0
#define MINIMUM(x,y)		(((x) < (y)) ? (x) : (y))
#define MAXIMUM(x,y)		(((x) > (y)) ? (x) : (y))
#define SQ(x)			((x)*(x))

typedef struct _Color4f{
	GLfloat red;
	GLfloat green;
	GLfloat blue;
	GLfloat alpha;
} Color4f;

typedef struct _Point3f{
	GLfloat		x;
	GLfloat		y;
	GLfloat		z;
	char		handy;
} Point3f;

typedef struct _Vector3f{
	GLfloat a;
	GLfloat b;
	GLfloat c;
} Vector3f;

typedef struct _PtrStruct{
	int same;
	int ID;
	Point3f *vertex1;
	Point3f *vertex2;
	Point3f arcVertex1;
	Point3f arcVertex2;
} PtrStruct;

float PntstoVector(Point3f *a, Point3f *b, Vector3f *vect);
double AngleBetweenUnitVector(Vector3f *V1, Vector3f *V2);
void PntstoVectorPtr(GLfloat *p1, GLfloat *p2, Vector3f *vect);

// calculates the normalized cross product of v1 to v2 and places it in v3
float NormalizeCross(Vector3f *v1, Vector3f *v2, Vector3f *v3);

// returns the distance between two points in 3 space, p and q
double magnitude3d(Point3f *p,Point3f *q);
double magnitude3v(Vector3f *v);

// returns 1 if the point is on or between the endpoints of the line
// returns 0 if the point doesn't fall within the line segment
// returns -1 if not sure why?
int DistancePointLine(Point3f *point, Point3f *start, Point3f *end, double *distance);

// Calculates if two lines intersect eachother sets the point at which they do to intersect
// returns 0 if they don't intersect and sets intersect to p2
// returns 1 if they do and sets intersect accordingly
int SegmentIntersect(Point3f *p1, Point3f *p2, Point3f *p3, Point3f *p4, Point3f *intersect);

int SegmentIntersectArc(Point3f *p1, Point3f *p2, Point3f *cc, float r, Point3f *Isect1, Point3f *Isect2);